﻿///  Copyright (c) 2010 Ray Liang (http://www.dotnetage.com)
///  Dual licensed under the MIT and GPL licenses:
///  http://www.opensource.org/licenses/mit-license.php
///  http://www.gnu.org/licenses/gpl.html

using System;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.ComponentModel.Design;
using System.Web.UI.Design.WebControls;
using System.Web.UI.Design;
using System.IO;

namespace DNA.UI.JQuery.Design
{
    public class ButtonDesigner : ControlDesigner
    {
        private ButtonEx button;

        public override void Initialize(IComponent component)
        {
            button = component as ButtonEx;
            base.Initialize(component);
        }

        public override bool AllowResize
        {
            get
            {
                return true;
            }
        }

        public override string GetDesignTimeHtml()
        {
            StringBuilder stringBuilder = new StringBuilder();
            StringWriter stringWriter = new StringWriter(stringBuilder);
            HtmlTextWriter writer = new HtmlTextWriter(stringWriter);

            writer.WriteBeginTag("button");
            writer.WriteAttribute("class", "ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only");
            writer.WriteAttribute("style", "overflow:visible");
            writer.WriteAttribute("value",button.Text);
            writer.WriteAttribute("type", "submit");
            writer.WriteAttribute("role", "button");
            writer.Write(HtmlTextWriter.TagRightChar);

            if (!string.IsNullOrEmpty(button.LeftIconCssClass))
            {
                writer.WriteBeginTag("span");
                writer.WriteAttribute("style", "width:16px;height:16px;float:left;");
                writer.WriteAttribute("class", "ui-button-icon-primary ui-icon "+button.LeftIconCssClass);
                writer.Write(HtmlTextWriter.TagRightChar);
                writer.WriteEndTag("span");
            }

            writer.WriteBeginTag("span");
            writer.WriteAttribute("style", "float:left;white-space:nowrap;");
            writer.WriteAttribute("class", "ui-button-text");
            writer.Write(HtmlTextWriter.TagRightChar);
            if (!string.IsNullOrEmpty(button.Text) && (button.ShowText))
                writer.Write(button.Text);
            writer.WriteEndTag("span");

            if (!string.IsNullOrEmpty(button.RightIconCssClass))
            {
                writer.WriteBeginTag("span");
                writer.WriteAttribute("style", "width:16px;height:16px;float:left;");
                writer.WriteAttribute("class", "ui-button-icon-secondary ui-icon " + button.RightIconCssClass);
                writer.Write(HtmlTextWriter.TagRightChar);
                writer.WriteEndTag("span");
            }

            writer.WriteEndTag("button");
            return stringBuilder.ToString();

            //return base.GetDesignTimeHtml();
        }

    }
}
